<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>1_字符串形式ref</title>
  </head>
  <body>
    <!-- 准备号一个容器 -->
    <div id="test"></div>
    <div id="test2"></div>
    <div id="test3"></div>

    <!-- 引入react核心库 -->
    <script type="text/javascript" src="../js/react.development.js"></script>
    <!-- 引入react-dom，用于支持react dom操作 -->
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <!-- 引入babel，用于将jsx转为js -->
    <script type="text/javascript" src="../js/babel.min.js"></script>
    <script type="text/babel">
      // 1. 创建类组件
      class MyComponent extends React.Component {
        showTips = () => {
          const { input1 } = this.refs
          alert(input1.value)
        }

        showTips2 = () => {
          const { input2 } = this.refs
          alert(input2.value)
        }

        render() {
          return (
            <div>
              <input ref="input1" type="text" placeholder="点击按钮提示" />
              &nbsp;
              <button ref="btn1" onClick={this.showTips}>
                点我提示
              </button>
              &nbsp;
              <input ref="input2" type="text" placeholder="失去焦点提示数据" onBlur={this.showTips2} />
            </div>
          )
        }
      }

      // 2. 渲染组件到页面
      ReactDOM.render(<MyComponent />, document.getElementById('test'))
    </script>
  </body>
</html>
